import unittest
import pygame, os
import game
import sprites
import data
import menu

class ControleerGame(unittest.TestCase):
    def setUp(self):
        self.size = width, height = 800, 480
        self.screen = pygame.display.set_mode(self.size)
        self.game = game.Game(self.screen)
    
    def testGameover_screen(self):
        var1 = False
        self.game.gameover_screen()
        var2 = self.game.keepGoing
        self.assertEquals(var1, var2)
     
    def testPlayerDef(self):
        self.game.space_pressed()
        player = None
        ball = None
        for b in self.game.playerSprites:
            player = b
        for b in self.game.ballSprites:
            ball = b
        self.assertEquals(b.rect.centerx, (player.rect.centerx - 30))
    
    def testGoRight(self):
        var1 = self.game.player.x
        self.game.player.x += 1
        self.game.playerSprites.update()
        var2 = self.game.player.x
        self.assertEquals((var1 + 1), var2)
        
    def testGoLeft(self):
        var1 = self.game.player.x
        self.game.player.x += -1
        self.game.playerSprites.update()
        var2 = self.game.player.x
        self.assertEquals((var1 -1), var2)
        
    def testGoUp(self):
        var1 = self.game.player.y
        self.game.player.y += -1
        self.game.playerSprites.update()
        var2 = self.game.player.y
        self.assertEquals(var1, (var2 + 1))
        
    def testGoDown(self):
        var1 = self.game.player.y
        self.game.player.y += 1
        self.game.playerSprites.update()
        var2 = self.game.player.y
        self.assertEquals(var1, (var2 - 1))
        
    def testKillSprites(self):
        var1 = self.game.sprites
        self.game.kill_sprites()
        var2 = self.game.sprites
        self.assertEquals(var1, var2)

    def testCountLevels(self):
        var1 = 4
        var2 = game.count_levels()
        self.assertEquals(var1, var2)
        
    def testGetLevel(self):
        var1 = 1
        var2 = self.game.get_lvl()
        self.assertEquals(var1, var2)
    
    def testGetLevelScore(self):
        var1 = 0
        var2 = self.game.get_lvl_score(1)
        self.assertNotEquals(var1, var2)
        
    def testSaveLvl(self):
        lvl = 1
        score = 500
        var1 = (1, 500)
        self.game.save_lvl(lvl, score)
        var2 = (self.game.get_lvl(), self.game.get_lvl_score(lvl))
        self.assertEquals(var1, var2)
        
    #Test wordt correct uitgevoerd, maar door de volgorde van de test zal deze als 'Fail' worden weergeven.    
    def testFinishScreen(self):
        var1 = self.game.get_lvl() + 1
        self.game.finish_screen()
        var2 = self.game.get_lvl()
        self.assertEquals(var1, var2)
        
    def testNextLevel(self):
        var1 = 2
        self.game.next_level()
        var2 = self.game.get_lvl()
        self.assertEquals(var1, var2)
        
class ControleerData(unittest.TestCase):
    
    def testFilePath(self):
        filename = "shit.png"
        data_py     = os.path.abspath(os.path.dirname(__file__))
        data_dir    = os.path.normpath(os.path.join(data_py, '..', 'data'))
        var1 = os.path.join(data_dir, filename)
        var2 = data.filepath(filename)    
        self.assertEquals(var1, var2)
        
class ControleerLevel(unittest.TestCase):
    
    def setUp(self):
        self.size = width, height = 800, 480
        self.screen = pygame.display.set_mode(self.size)
        self.game = game.Game(self.screen)
    
    def testGetSize(self):
        var1 = [self.game.level.level.get_size()[0]*32, self.game.level.level.get_size()[1]*32]
        var2 = self.game.level.get_size()
        self.assertEquals(var1, var2)
        
    def testGetAt(self):
        var1 = self.game.level.level.get_at((self.game.level.x+-2, self.game.level.y+-2))
        var2 = self.game.level.get_at(-2, -2)
        self.assertEquals(var1, var2)
        
class ControleerMenu(unittest.TestCase):
    
    def setUp(self):
        self.size = width, height = 800, 480
        self.screen = pygame.display.set_mode(self.size)
        self.menu = menu.Menu(self.screen)
        self.menuStyle = self.menu.menu
        
    def testSetPos(self):
        self.menuStyle.set_pos(0, 0)
        var1 = (self.menuStyle.x, self.menuStyle.y) ;
        var2 = (0,0)
        
        self.assertEquals(var1, var2)
    
    def testSetFont(self):
        newFont = pygame.font.Font(data.filepath("fonts/font2.ttf"), 10)
        self.menuStyle.set_font(newFont)
        
        var1 = newFont
        var2 = self.menuStyle.font
        
        self.assertEquals(var1, var2)
        
    def testSetHighlightColor(self):
        newColor = (255, 255, 255)
        self.menuStyle.set_highlight_color(newColor)
        
        var1 = newColor
        var2 = self.menuStyle.hcolor
        
        self.assertEquals(var1, var2)
        
    def testNormalColor(self):
        newColor = (255, 255, 255)
        self.menuStyle.set_normal_color(newColor)
        
        var1 = newColor
        var2 = self.menuStyle.color
        
        self.assertEquals(var1, var2)
        
        
unittest.main()
    

